package cheesymock;

import java.lang.reflect.*;

/**
 * Return a 'intuitive' default return value depending on the return
 * type of the given method:
 *
 * <ul>
 * <li>Methods with an Object return type return null..</li>
 * <li>Methods with numeric types or the byte type return zero.</li>
 * <li>Methods with a boolean type return false.</li>
 * <li>Methods with a char type return the character \u0000.</li>
 * </ul>
 *
 * @author fredrik
 */
public class NullDefaultReturn implements DefaultReturn {
	public Object value(Method method) {
		Object returnType = method.getReturnType();
		if (Integer.TYPE.equals(returnType)) {
			return Integer.valueOf(0);
		} else if (Boolean.TYPE.equals(returnType)) {
			return Boolean.valueOf(false);
		} else if (Long.TYPE.equals(returnType)) {
			return Long.valueOf(0);
		} else if (Float.TYPE.equals(returnType)) {
			return new Float(0);
		} else if (Double.TYPE.equals(returnType)) {
			return new Double(0);
		} else if (Character.TYPE.equals(returnType)) {
			return Character.valueOf('\u0000');
		} else if (Byte.TYPE.equals(returnType)) {
			return Byte.valueOf((byte) 0);
		} else if (Short.TYPE.equals(returnType)) {
			return Short.valueOf((short) 0);
		} 
		return null;
	}
}